package com.uye.framework.util;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Collection;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class StringUtils {

	public static String toJSONString(Object o){
		return JSONObject.fromObject(o).toString();
	}
	
	@SuppressWarnings("rawtypes")
	public static String toJSONString(Collection c){
		return toJSONString("list",c);
	}
	@SuppressWarnings("rawtypes")
	public static String toJSONString(String collectionName, Collection c){
		return "{"+collectionName+":"+JSONArray.fromObject(c).toString()+"}";
	}

	public static String toString(Exception e){
	    StringWriter sw = new StringWriter();
	    PrintWriter pw = new PrintWriter(sw);
	    e.printStackTrace(pw);	    
	    return sw.toString();
	}
}
